package com.leo;

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.Shape;
import javafx.stage.Stage;

/**
 * @ClassName Calculate
 * @Description 图形计算，intersect相交，subtract减去，union合并，clip修剪
 * @Author wangss
 * @date 2020.07.04 17:49
 * @Version 1.0
 */
public class CalculateDemo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        AnchorPane an = new AnchorPane();

        HBox hBox = new HBox(20);
        hBox.setAlignment(Pos.CENTER);

        Circle circle = new Circle(100);
        circle.setCenterX(100);
        circle.setCenterY(100);

        ImageView iv = new ImageView("/images/24.png");
        iv.setFitWidth(100);
        iv.setPreserveRatio(true);
        iv.setX(30);

        // 裁剪
        iv.setClip(circle);


        Circle circle1 = new Circle(100);
        circle1.setFill(Color.RED);
        circle1.setCenterX(100);
        circle1.setCenterY(100);

        Rectangle rectangle = new Rectangle(200, 100);
        rectangle.setFill(Color.BLUE);
        rectangle.setX(200);
        rectangle.setY(50);

        // 交接
        Shape intersect = Shape.intersect(circle1, rectangle);

        hBox.getChildren().addAll(iv, intersect);
        an.getChildren().add(hBox);
        AnchorPane.setTopAnchor(hBox, 50d);
        AnchorPane.setLeftAnchor(hBox, 50d);

        Scene scene = new Scene(an);
        primaryStage.setScene(scene);
        primaryStage.setHeight(1000d);
        primaryStage.setWidth(1500d);
        primaryStage.setAlwaysOnTop(true);
        primaryStage.show();
    }
}
